package sedh.project

import grails.test.*


class ProgramaTests extends GrailsUnitTestCase {

	def prog
	protected void setUp() {
		super.setUp()
		
		mockForConstraintsTests(Programa)
		prog = new Programa(nome: "Programa1", descricao: "Descricao1")
	}

	protected void tearDown() {
		super.tearDown()
	}

	void testUnique() {
		def igual = new Programa(nome: "Programa1", descricao : "Descricao1")
		mockForConstraintsTests(Programa, [igual])
		
		assertFalse prog.validate()
		
		prog = new Programa(nome: "OutroPrograma", descricao : "Descricao1")
		assertTrue prog.validate()
		
	}

	void testBlank() {
		prog = new Programa(name: '', descricao: '')
		assertFalse prog.validate()
		

		prog = new Programa(nome: "Programa1", descricao: "Descricao1")
		assertTrue prog.validate()
	}
	
	void testNullable() {
		prog = new Programa()
		assertFalse prog.validate()
		assertEquals 'Nome eh null.', 'nullable', prog.errors['nome']
		assertEquals 'Descricao eh null', 'nullable', prog.errors['descricao']
		
	}
	
	void testMaxSize() {
		prog.nome = 'This name is just way longer than the maxSize argument defines.This name is just way longer than the maxSize argument defines.'
		prog.descricao = 'The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.The nickName is just too long, people will not remember this.'
		assertFalse prog.validate()
		assertEquals 'Nome muito grande.', 'size', prog.errors['nome']
		assertEquals 'Descricao muito grade.', 'maxSize', prog.errors['descricao']

		prog.nome = 'Programa2'
		prog.descricao = 'Um texto razoavelmente bom para uma pequena descricao'
		assertTrue prog.validate()
	}
	
	void testMinSize() {
		prog.nome = "s"
		assertFalse prog.validate()
		assertEquals 'Nome muito pequeno.', 'size', prog.errors['nome']
		
		prog.nome = "NM"
		assertTrue prog.validate()
		
	}
}
